﻿using System.Windows;
#if WPF
using System.Windows.Controls;

#else
using Windows.UI.Xaml.Controls;
using Windows.Foundation;
using Windows.UI.Xaml.Data;
#endif

namespace Eternal.DataVisualization
{
#if WPF_UN
    public class Legend : System.Windows.Controls.WrapPanel
#else
    public class Legend : WrapPanel
#endif
    {
        internal Chart Chart;

        ContentControl control;

        internal void UpdateLegned(Size size)
        {
            Children.Clear();
            if (Chart != null)
            {
                foreach (var series in Chart.UISeries)
                {
                    var seriesType = series.GetType().Name;
                    control = new ContentControl { DataContext = series };
                    if (series.LegendTemplate != null)
                        control.Template = series.LegendTemplate;
                    else
                    {
                        control.Template = DataResource.GetLegendResource[seriesType] as ControlTemplate;
                    }
                    Children.Add(control);
                }
            }
        }        

        //protected override Size MeasureOverride(Size constraint)
        //{
        //    size = constraint;
        //    if (!updated)
        //        UpdateLegned();
        //    return base.MeasureOverride(constraint);
        //}

    }
}
